<template>
	<view>
		<view class="gray-box">
			<view class="date-change-box">
				<!-- <image class="icon" src="/static/appointment/time-left.png"></image> -->
				<text>{{doctorVisitPlan.day | getDate}} {{doctorVisitPlan.day}}</text>
			<!-- 	<image class="icon" src="/static/appointment/time-right.png"></image> -->
			</view>
			<view class="time-money-box" v-for="(item, index) in visitPlan.residues"
			 :key="index" @click="toInsureAppoint(item, index)">
				<view class="time-box">
					<view class="time-button">{{timeList[index][0]}}</view>
					<view class="time-button">{{timeList[index][1]}}</view>
				</view>
				<view class="appoint-num" style='width:32%;' v-if="item == -1" >
					<text>已过时间</text>
					<image class="icon"></image>
				</view>
				<view class="appoint-num" style='width:32%;' v-if="item == 0" >
					<text>已被预约</text>
					<image class="icon"></image>
				</view>
				<view class="appoint-num" style='width:32%;' v-if="item == -2" >
					<text>已被预约</text>
					<image class="icon"></image>
				</view>
				<view class="appoint-num" v-if="item > 0">
					<text>可预约</text>
					<image class="icon" src="/static/icon-right.png"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {getVisitPlanList, getMassageVisitPlan} from '@/common/api/doctor.js'
	import {formDate} from '@/common/js/formDate.js'
	import {error} from '@/common/js/errorTips.js'
	export default {
		props: {
			
		},
		data() {
			return {
				doctorVisitPlan: {},
				doctorInfo: {},
				visitPlan: {},
				timePeriods: '',
				timeList: []
			}
		},
		methods: {
			// 跳转到确认挂号页面
			toInsureAppoint: function(item, index) {
				if(item <= 0) return
				let timePeriod = index+1
				let visitInfo = {
					planId: this.visitPlan.id,
					doctorName: this.doctorInfo.name,
					time: this.timeList[index][0]+'-'+this.timeList[index][1],
					timePeriod: timePeriod,
					date: this.visitPlan.day,
					clinicId: this.visitPlan.clinicId,
					doctorId: this.doctorInfo.id
				}
				uni.setStorageSync('visitInfo', JSON.stringify(visitInfo))
				uni.navigateTo({
					url: '/pagesB/pages/appointPages/doctorAppointDetail/insureAppoint/insureAppoint'
				})
			},
		// 获取医生的该天的出诊计划
			getDoctorVisitPlan: function() {
				uni.showLoading({
					title: '加载中'
				})
				//获取当前选择日期的医生号源信息
				let date = uni.getStorageSync('currentDate')
				this.doctorVisitPlan.day = date
				let that = this;
				getMassageVisitPlan(JSON.parse(uni.getStorageSync('massage')).id, this.doctorInfo.id, date).then(res => {
					//console.log(res)
					if(res.data.code === 200) {
						uni.hideLoading()
						//将返回过来的数据中的时间段传给timePeriod
						res.data.data.forEach(function(item) {
							//console.log("doctorVisitPlanTime"+that.doctorVisitPlan.time)
							that.visitPlan = item
							that.timePeriods = item.duan
							// console.log('时间段'+that.timePeriods)
							that.getTimePeriod()
							// if(that.doctorVisitPlan.time === item.time) {
							// 	that.visitPlan = item
							// }
						})
					}
				}).catch(() => {
					uni.hideLoading();
					error('获取出诊计划失败')
				})
			},
			//分割后端返回的时间段
			getTimePeriod:function(){
				//储存分割好的时间段
				let timePeriod = []
				//以逗号作为分隔符分割日期字符串
				let arr =  this.timePeriods.split(',')
				//console.log(this.timePeriods)
				 arr.forEach(item => {
				 	timePeriod.push(item.split('-'))
				 })
				 this.timeList = timePeriod
				 console.log(this.timeList)
			}
		},
		created() {
		this.doctorVisitPlan = JSON.parse(uni.getStorageSync('doctorInfo')).outCallList
	    //console.log("doctorVisitPlan是:"+this.doctorVisitPlan.day)
		this.doctorInfo = JSON.parse(uni.getStorageSync('doctorInfo')).doctorInfo
		this.getDoctorVisitPlan()
		uni.removeStorageSync("doctorInfo")
		}
	}
</script>

<style lang="scss">
	@import '@/common/scss/common.scss';
	.gray-box{
		@extend .gray-border-box;
		margin-top: 30rpx;
		.date-change-box{
			@include width-margin(90%,100rpx);
			@include flex-direction(row);
			justify-content: center;
			align-items: center;
			border-bottom: 1px solid $border-color;
			.icon{
				@include icon-size(60rpx,60rpx);
			}
			.date-day{
				@include font-style(18px,bold,#000000);
			}
		}
		.time-money-box{
			@include width-margin(90%,170rpx);
			@include flex-direction(row);
			justify-content: space-between;
			align-items: center;
			.time-box{
				width: 30%;
				height: 100%;
				margin: 20rpx 0;
				.time-button{
					width: 130rpx;
					height: 55rpx;
					line-height: 55rpx;
					text-align: center;
					background: $major-color;
					margin-top: 20rpx;
					border-radius: 6px;
					overflow: hidden;
					@include font-style(16px,500,#ffffff);
				}
				.gray-background{
					background: #D1D1D1 !important;
				}
			}
			.money{
				width: 40%;
				@include font-style(16px,500,#000000);
				// 多少钱的数字的颜色为#FFD39B
			}
			.appoint-num{
				width: 30%;
				display: flex;
				justify-content: flex-end;
				@include font-style(16px,500,$gray-color);
				align-items: center;
				.icon{
					@include icon-size(60rpx,60rpx);
					// margin-left: 10rpx;
				}
			}
		}
		.time-money-box:not(:last-child){
			border-bottom: 1px solid $border-color;
		}
	}
</style>
